<template>
  <div>
    <!--面包屑导航区-->
    <my-bread level1="订单管理" level2="订单列表"></my-bread>
    <el-card>
      <!--表格展示-->
      <el-table :data="orderList" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column label="是否付款">
          <template slot-scope="scope">
              <el-tag v-if="scope.row.order_pay === '0'">已付款</el-tag>
              <el-tag v-else-if="scope.row.order_pay === '1'" type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="scope">
              <div>{{scope.row.create_time | fmtDate}}</div>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button-group>
              <el-button type="primary" icon="el-icon-edit" size="mini" @click="showEditDialog(scope.row.id)"></el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[1, 2, 4, 6]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>
    <!-- 修改用户对话框 -->
    <el-dialog
      title="修改用户"
      :visible.sync="editDialogVisible"
      width="50%">
      <el-form :model="editForm" ref="editFormRef" label-width="70px">
        <el-form-item label="省市区" readonly>
          {{selectedOptions}}
          <!--级联选择器-->
            <el-cascader
            :options="list"
            v-model="selectedOptions"
            :props="{ expandTrigger: 'hover' }"
            @change="handleChange" clearable></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="email">
          <el-input v-model="editForm.email"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editOrder">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
// npm install element-china-area-data -S 省市区级联数据
// 在.vue中可以引入.js库插件(swiper.js/zepto.js/iscroll.js下拉刷新上拉加载更多/wow.js整屏滚动) vue-swiper
import { regionData } from 'element-china-area-data'
export default {
  data() {
    return {
      orderList: [],
      queryInfo: {
        pagenum: 1,
        pagesize: 4
      },
      total: 0,
      editDialogVisible: false,
      editForm: {},
      // 级联选择器绑定数据
      list: [],
      selectedOptions: []
    }
  },
  created() {
    this.getOrderList()
  },
  methods: {
    async getOrderList() {
      const { data: res } = await this.$http.get('orders', { params: this.queryInfo })
      console.log(res)
      if (res.meta.status !== 200) return this.$message.error('获取订单列表失败')
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    // 监听pagesize改变
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    // 监听页码值改变
    handleCurrentChange(newPage) {
      this.queryInfo.pagenum = newPage
      this.getOrderList()
    },
    showEditDialog() {
      this.editDialogVisible = true
      this.list = regionData
    },
    handleChange() {},
    editOrder() {}
  }
}
</script>

<style>

</style>
